
//
//  UIBarButton.swift
//  Weibo
//
//  Created by 杨军民 on 16/7/23.
//  Copyright © 2016年 杨军民. All rights reserved.
//

import UIKit

/*
1、扩展只能有便利构造函数
便利构造函数需要调用一个自己的便利构造函数(保证便利构造函数会调用到指定构造函数)或指定构造函数

*/

extension UIBarButtonItem {
    
    convenience init(imageName: String ) {
        
        let button = UIButton(type: UIButtonType.Custom)
        //普通状态
        button.setImage(UIImage(named:imageName), forState: UIControlState.Normal)
        //高亮状态
        button.setImage(UIImage(named: imageName+"_highlighted"), forState: UIControlState.Highlighted)
        button.sizeToFit()
        self.init(customView:button)
    }
    
    //    class func createBarButtonItem(imageName: String) -> UIBarButtonItem {
    //        let button = UIButton(type: UIButtonType.Custom)
    //        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
    //        button.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
    //        button.sizeToFit()
    //
    //        return UIBarButtonItem(customView: button)
    //    }
    
}

